const myArray = [1, 2, [3, 4, 5, [6, [7]]], 8, [9]]

var flat = function*(array) {
	for (var i = 0; i < array.length; i++) {
		if (Array.isArray(array[i])) { //判断数组的每个元素是否为数组
			yield* flat(array[i]);
		} else {
			yield array[i];
		}
	}
};
const flatArray = [...flat(myArray)]
console.log(flatArray);
//[1, 2, 3, 4, 5, 6, 7, 8, 9]
